package com.xique.door.service.impl;


import com.xique.common.core.text.Convert;
import com.xique.common.core.utils.DateUtils;
import com.xique.common.core.utils.SecurityUtils;
import com.xique.door.bean.domain.Elevator;
import com.xique.door.bean.domain.ElevatorCommunityInfo;
import com.xique.door.bean.search.ElevatorListSearch;
import com.xique.door.bean.vo.elevator.ElevatorCountInAreaStatisticVO;
import com.xique.door.bean.vo.elevator.ElevatorGeneralVO;
import com.xique.door.bean.vo.elevator.ElevatorInfoListWebVO;
import com.xique.door.bean.vo.elevator.ElevatorServiceInfoStatisticVO;
import com.xique.door.mapper.ElevatorMapper;
import com.xique.door.service.IElevatorService;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * 电梯设备Service业务层处理
 *
 * @author caogq
 * @date 2021-10-08
 */
@Service
public class ElevatorServiceImpl implements IElevatorService
{
    @Autowired
    private ElevatorMapper elevatorMapper;

    /**
     * 查询电梯设备
     *
     * @param id 电梯设备ID
     * @return 电梯设备
     */
    @Override
    public Elevator selectElevatorById(Long id)
    {
        return elevatorMapper.selectElevatorById(id);
    }

    /**
     * 查询电梯设备列表
     *
     * @param elevator 电梯设备
     * @return 电梯设备
     */
    @Override
    public List<Elevator> selectElevatorList(Elevator elevator)
    {
        return elevatorMapper.selectElevatorList(elevator);
    }

    @Override
    public List<Elevator> selectElevatorTaskList(Elevator elevator) {
        return elevatorMapper.selectElevatorTaskList(elevator);
    }

    @Override
    public List<ElevatorInfoListWebVO> selectElevatorList(ElevatorListSearch search) {
        return elevatorMapper.selectElevatorInfoList(search);
    }

    /**
     * 新增电梯设备
     *
     * @param elevator 电梯设备
     * @return 结果
     */
    @Override
    public int insertElevator(Elevator elevator)
    {
        elevator.setCreateTime(DateUtils.getNowDate());
        elevator.setUpdateTime(elevator.getCreateTime());
        elevator.setCreateBy(String.valueOf(SecurityUtils.getUserId()));
        elevator.setUpdateBy(elevator.getCreateBy());
        return elevatorMapper.insertElevator(elevator);
    }

    /**
     * 修改电梯设备
     *
     * @param elevator 电梯设备
     * @return 结果
     */
    @Override
    public int updateElevator(Elevator elevator)
    {
        elevator.setUpdateTime(DateUtils.getNowDate());
        elevator.setUpdateBy(String.valueOf(SecurityUtils.getUserId()));
        return elevatorMapper.updateElevator(elevator);
    }

    /**
     * 删除电梯设备对象
     *
     * @param ids 需要删除的数据ID
     * @return 结果
     */
    @Override
    public int deleteElevatorByIds(String ids)
    {
        return elevatorMapper.deleteElevatorByIds(Convert.toStrArray(ids));
    }

    /**
     * 删除电梯设备信息
     *
     * @param id 电梯设备ID
     * @return 结果
     */
    @Override
    public int deleteElevatorById(Long id)
    {
        return elevatorMapper.deleteElevatorById(id);
    }

    @Override
    public List<ElevatorCommunityInfo> selectElevatorCommunityInfoByParkIds(List<Long> parkIds) {
        if (CollectionUtils.isEmpty(parkIds)) {
            return new ArrayList<>();
        }
        return elevatorMapper.selectElevatorCommunityInfoByParkIds(parkIds);
    }

    @Override
    public List<ElevatorCommunityInfo> selectElevatorCommunityInfoBySearch(String content) {
        return elevatorMapper.selectElevatorCommunityInfoBySearch(content);
    }

    @Override
    public ElevatorCommunityInfo selectElevatorCommunityInfoByParkId(Long parkId) {
        return elevatorMapper.selectElevatorCommunityInfoByParkId(parkId);
    }

    @Override
    public List<Elevator> selectElevatorByAddressCode(Long code) {
        return elevatorMapper.selectElevatorByAddressCode(code);
    }

    @Override
    public int selectElevatorCountByParkId(Long parkId) {
        return elevatorMapper.selectElevatorCountByParkId(parkId);
    }

    @Override
    public int selectElevatorCountByAddressCode(Long code) {
        return elevatorMapper.selectElevatorCountByAddressCode(code);
    }

    @Override
    public List<ElevatorCountInAreaStatisticVO> selectElevatorCountByAddressCodes(List<String> list, int level) {
        return elevatorMapper.selectElevatorCountByAddressCodes(list, level);
    }

    @Override
    public ElevatorServiceInfoStatisticVO selectElevatorServiceInfoCountByParkId(Long parkId) {
        return elevatorMapper.selectElevatorServiceInfoCountByParkId(parkId);
    }

    @Override
    public ElevatorServiceInfoStatisticVO selectElevatorServiceInfoCountByAddressCode(Long code) {
        return elevatorMapper.selectElevatorServiceInfoCountByAddressCode(code);
    }

    @Override
    public List<String> selectElevatorSecurityRankingByAddressCode(Long code) {
        return elevatorMapper.selectElevatorSecurityRankingByAddressCode(code);
    }

    @Override
    public ElevatorGeneralVO selectElevatorGeneralByAddressCode(Long code) {
        return elevatorMapper.selectElevatorGeneralByAddressCode(code);
    }
}
